package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.activity.CommendDetails;
import com.bilibili.bilibili.model.RecommendModel;
import com.bilibili.bilibili.utils.GlideImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：bilibili
 * 类描述：
 * 创建人：${丁江楠}
 * 创建时间：2017/3/10 18:57
 * 修改人：${丁江楠}
 * 修改时间：2017/3/10 18:57
 * 修改备注：
 */
public class CommendAdapter extends RecyclerView.Adapter<CommendAdapter.MyViewHolder>{
    private Context context;
    private List<RecommendModel.DataBean> list=new ArrayList<>();
    private OnItemclistener myitemclistener;


    public void setMyitemclistener(OnItemclistener myitemclistener) {
        this.myitemclistener = myitemclistener;
    }

    public CommendAdapter(Context context, List<RecommendModel.DataBean> list) {
        this.context = context;
        this.list = list;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder viewHolder=new MyViewHolder(View.inflate(context,R.layout.item_recommend,null));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        RecommendModel.DataBean dataBean = list.get(position);
        GlideImageLoader imageLoader=new GlideImageLoader();
        imageLoader.displayImage(context,dataBean.getCover(),holder.imageView);
        holder.text_title.setText(dataBean.getTitle());
        holder.text_play.setText(dataBean.getPlay()+"");
        holder.text_tname.setText(dataBean.getTname());
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"点击了",Toast.LENGTH_LONG).show();
                Intent intent=new Intent(context, CommendDetails.class);
                context.startActivity(intent);
            }
        });
    }
    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{

        private final ImageView imageView;
        private final TextView text_play;
        private final TextView text_title;
        private final TextView text_tname;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.recommend_imageView);
            text_play = (TextView) itemView.findViewById(R.id.text_play);
            text_title = (TextView) itemView.findViewById(R.id.text_title);
            text_tname = (TextView) itemView.findViewById(R.id.text_tname);
        }
    }
    public interface OnItemclistener{
        void onItemclick(View view,int position);
    }
}
